{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9ac3cde2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0f41184",
   "metadata": {},
   "source": [
    "## Test new YFinance Tool"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "24fbcb71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭─────────────────── </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">Tool Usage Summary (2 tools)</span><span style=\"color: #008080; text-decoration-color: #008080\"> ───────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"font-weight: bold\"> Tool Name           Parameters          Result             </span>       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_info</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"address1\": \"One</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">Apple Park Way\",</span>          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"city\":...</span>              <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_analyst_recom…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{\"0\":{\"period\":\"0…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m──────────────────\u001b[0m\u001b[36m \u001b[0m\u001b[1;36mTool Usage Summary (2 tools)\u001b[0m\u001b[36m \u001b[0m\u001b[36m──────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1m \u001b[0m\u001b[1mTool Name\u001b[0m\u001b[1m         \u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m\u001b[1mParameters\u001b[0m\u001b[1m        \u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m\u001b[1mResult\u001b[0m\u001b[1m            \u001b[0m\u001b[1m \u001b[0m       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_info\u001b[0m    \u001b[33m{\"symbol\": \"AAPL\"}\u001b[0m  \u001b[32m{\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"address1\": \"One\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32mApple Park Way\",\u001b[0m          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"city\":...\u001b[0m              \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_analyst_recom…\u001b[0m  \u001b[33m{\"symbol\": \"AAPL\"}\u001b[0m  \u001b[32m{\"0\":{\"period\":\"0…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭────────────────────── </span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; font-weight: bold\">Upsonic - Call Result</span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\"> ───────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">LLM Model:</span>        openai/gpt-4o                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Result:</span>           <span style=\"color: #008000; text-decoration-color: #008000\">### Apple Inc. (AAPL) Company </span>                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Information:</span>                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Industry**: Consumer Electronics</span>            <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Sector**: Technology</span>                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Address**: One Apple Park Way, </span>             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Cupertino, CA, 95014, United States</span>             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Website**: </span>                                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">[apple.com](https://www.apple.com)</span>              <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Business Summary**: Apple Inc. </span>             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">designs, manufactures, and markets </span>             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">smartphones, personal computers, </span>               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">tablets, wearables, and accessories. </span>           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">The[bold white]...[/bold white]</span>                 <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Response Format:</span>  &lt;class 'str'&gt;                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Estimated Cost:</span>   ~$0.0125$                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Time Taken:</span>       12.95 seconds                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m─────────────────────\u001b[0m\u001b[37m \u001b[0m\u001b[1;37mUpsonic - Call Result\u001b[0m\u001b[37m \u001b[0m\u001b[37m──────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mLLM Model:\u001b[0m        openai/gpt-4o                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResult:\u001b[0m           \u001b[32m### Apple Inc. (AAPL) Company \u001b[0m                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mInformation:\u001b[0m                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Industry**: Consumer Electronics\u001b[0m            \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Sector**: Technology\u001b[0m                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Address**: One Apple Park Way, \u001b[0m             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mCupertino, CA, 95014, United States\u001b[0m             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Website**: \u001b[0m                                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m[apple.com](https://www.apple.com)\u001b[0m              \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Business Summary**: Apple Inc. \u001b[0m             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mdesigns, manufactures, and markets \u001b[0m             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32msmartphones, personal computers, \u001b[0m               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mtablets, wearables, and accessories. \u001b[0m           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mThe[bold white]...[/bold white]\u001b[0m                 \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResponse Format:\u001b[0m  <class 'str'>                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mEstimated Cost:\u001b[0m   ~$0.0125$                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mTime Taken:\u001b[0m       12.95 seconds                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080\">╭──────────────────── </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Upsonic - Price ID Summary</span><span style=\"color: #800080; text-decoration-color: #800080\"> ────────────────────╮</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Price ID:</span>              <span style=\"color: #800080; text-decoration-color: #800080\">afd919b6-c70f-4c04-beae-39b152697f…</span>        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>                                                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Input Tokens:</span>          <span style=\"color: #800080; text-decoration-color: #800080\">3,648</span>                                      <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Output Tokens:</span>         <span style=\"color: #800080; text-decoration-color: #800080\">334</span>                                        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Total Estimated Cost:</span>  <span style=\"color: #800080; text-decoration-color: #800080\">$0.0125</span>                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[35m╭─\u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m \u001b[0m\u001b[1;35mUpsonic - Price ID Summary\u001b[0m\u001b[35m \u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mPrice ID:\u001b[0m              \u001b[35mafd919b6-c70f-4c04-beae-39b152697f…\u001b[0m        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m                                                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mInput Tokens:\u001b[0m          \u001b[35m3,648\u001b[0m                                      \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mOutput Tokens:\u001b[0m         \u001b[35m334\u001b[0m                                        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mTotal Estimated Cost:\u001b[0m  \u001b[35m$0.0125\u001b[0m                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "### Apple Inc. (AAPL) Company Information:\n",
      "\n",
      "- **Industry**: Consumer Electronics\n",
      "- **Sector**: Technology\n",
      "- **Address**: One Apple Park Way, Cupertino, CA, 95014, United States\n",
      "- **Website**: [apple.com](https://www.apple.com)\n",
      "- **Business Summary**: Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories. They provide various services including AppleCare, cloud services, and operate platforms like the App Store. They offer subscription-based services such as Apple Music, Apple TV+, and Apple Pay.\n",
      "- **CEO**: Mr. Timothy D. Cook\n",
      "- **Market Cap**: $3.15 trillion\n",
      "- **Revenue**: $400.37 billion\n",
      "- **Employees**: Approximately 164,000\n",
      "\n",
      "### Analyst Recommendations for AAPL:\n",
      "\n",
      "- **Current Recommendations**:\n",
      "  - Strong Buy: 6 analysts\n",
      "  - Buy: 20 analysts\n",
      "  - Hold: 17 analysts\n",
      "  - Sell: 2 analysts\n",
      "  - Strong Sell: 1 analyst\n",
      "\n",
      "The average analyst rating is \"buy\" with a mean recommendation of 2.1 (out of 5, where 1 is \"strong buy\" and 5 is \"strong sell\"). The previous periods show consistency in recommendations, indicating a stable outlook among analysts.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'### Apple Inc. (AAPL) Company Information:\\n\\n- **Industry**: Consumer Electronics\\n- **Sector**: Technology\\n- **Address**: One Apple Park Way, Cupertino, CA, 95014, United States\\n- **Website**: [apple.com](https://www.apple.com)\\n- **Business Summary**: Apple Inc. designs, manufactures, and markets smartphones, personal computers, tablets, wearables, and accessories. They provide various services including AppleCare, cloud services, and operate platforms like the App Store. They offer subscription-based services such as Apple Music, Apple TV+, and Apple Pay.\\n- **CEO**: Mr. Timothy D. Cook\\n- **Market Cap**: $3.15 trillion\\n- **Revenue**: $400.37 billion\\n- **Employees**: Approximately 164,000\\n\\n### Analyst Recommendations for AAPL:\\n\\n- **Current Recommendations**:\\n  - Strong Buy: 6 analysts\\n  - Buy: 20 analysts\\n  - Hold: 17 analysts\\n  - Sell: 2 analysts\\n  - Strong Sell: 1 analyst\\n\\nThe average analyst rating is \"buy\" with a mean recommendation of 2.1 (out of 5, where 1 is \"strong buy\" and 5 is \"strong sell\"). The previous periods show consistency in recommendations, indicating a stable outlook among analysts.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from upsonic import Agent, Task\n",
    "from upsonic.tools import YFinanceTools\n",
    "\n",
    "# Instantiate your toolkit with the desired capabilities\n",
    "yfinance_tools = YFinanceTools(\n",
    "    company_info=True,\n",
    "    analyst_recommendations=True,\n",
    "    company_news=True\n",
    ")\n",
    "\n",
    "# Create a task, passing the toolkit's functions as tools\n",
    "task = Task(\n",
    "    \"Get company info and analyst recommendations for AAPL.\",\n",
    "    tools=yfinance_tools.functions()\n",
    ")\n",
    "\n",
    "agent = Agent(name=\"Stock Analyst\")\n",
    "\n",
    "# Run the task and print the result\n",
    "agent.print_do(task)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f04f7808",
   "metadata": {},
   "source": [
    "## Investment Analysis Report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0656fa06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭────────────────── </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">Tool Usage Summary (12 tools)</span><span style=\"color: #008080; text-decoration-color: #008080\"> ───────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"font-weight: bold\"> Tool Name           Parameters          Result             </span>       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_info</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"address1\": \"One</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">Apple Park Way\",</span>          <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"city\":...</span>              <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_info</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"MSFT\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"address1\": \"One</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">Microsoft Way\",</span>           <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  \"city\": ...</span>             <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_info</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": </span>         <span style=\"color: #008000; text-decoration-color: #008000\">{</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"GOOGL\"}</span>            <span style=\"color: #008000; text-decoration-color: #008000\">  \"address1\": </span>            <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">\"1600 Amphitheatre</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">Parkway\",</span>                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">  ...</span>                     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_current_stock…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">211.1600</span>                  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_current_stock…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"MSFT\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">503.3200</span>                  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_current_stock…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": </span>         <span style=\"color: #008000; text-decoration-color: #008000\">180.1900</span>                  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"GOOGL\"}</span>                                      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_analyst_recom…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{\"0\":{\"period\":\"0…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_analyst_recom…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"MSFT\"}</span>  <span style=\"color: #008000; text-decoration-color: #008000\">{\"0\":{\"period\":\"0…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_analyst_recom…</span>  <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": </span>         <span style=\"color: #008000; text-decoration-color: #008000\">{\"0\":{\"period\":\"0…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"GOOGL\"}</span>                                      <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_news</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"AAPL\",</span>  <span style=\"color: #008000; text-decoration-color: #008000\">[</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"num_stories\": 5}</span>   <span style=\"color: #008000; text-decoration-color: #008000\">  {</span>                       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">    \"id\": </span>                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">\"68b1079a-3666-36…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_news</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": \"MSFT\",</span>  <span style=\"color: #008000; text-decoration-color: #008000\">[</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"num_stories\": 5}</span>   <span style=\"color: #008000; text-decoration-color: #008000\">  {</span>                       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">    \"id\": </span>                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">\"8221f85a-11f6-35…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>  <span style=\"color: #008080; text-decoration-color: #008080\">get_company_news</span>    <span style=\"color: #808000; text-decoration-color: #808000\">{\"symbol\": </span>         <span style=\"color: #008000; text-decoration-color: #008000\">[</span>                         <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"GOOGL\", </span>           <span style=\"color: #008000; text-decoration-color: #008000\">  {</span>                       <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                      <span style=\"color: #808000; text-decoration-color: #808000\">\"num_stories\": 5}</span>   <span style=\"color: #008000; text-decoration-color: #008000\">    \"id\": </span>                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                          <span style=\"color: #008000; text-decoration-color: #008000\">\"a3c6b5e3-a60a-32…</span>        <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m─────────────────\u001b[0m\u001b[36m \u001b[0m\u001b[1;36mTool Usage Summary (12 tools)\u001b[0m\u001b[36m \u001b[0m\u001b[36m──────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1m \u001b[0m\u001b[1mTool Name\u001b[0m\u001b[1m         \u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m\u001b[1mParameters\u001b[0m\u001b[1m        \u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m\u001b[1mResult\u001b[0m\u001b[1m            \u001b[0m\u001b[1m \u001b[0m       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_info\u001b[0m    \u001b[33m{\"symbol\": \"AAPL\"}\u001b[0m  \u001b[32m{\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"address1\": \"One\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32mApple Park Way\",\u001b[0m          \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"city\":...\u001b[0m              \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_info\u001b[0m    \u001b[33m{\"symbol\": \"MSFT\"}\u001b[0m  \u001b[32m{\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"address1\": \"One\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32mMicrosoft Way\",\u001b[0m           \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  \"city\": ...\u001b[0m             \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_info\u001b[0m    \u001b[33m{\"symbol\": \u001b[0m         \u001b[32m{\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"GOOGL\"}\u001b[0m            \u001b[32m  \"address1\": \u001b[0m            \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m\"1600 Amphitheatre\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32mParkway\",\u001b[0m                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m  ...\u001b[0m                     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_current_stock…\u001b[0m  \u001b[33m{\"symbol\": \"AAPL\"}\u001b[0m  \u001b[32m211.1600\u001b[0m                  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_current_stock…\u001b[0m  \u001b[33m{\"symbol\": \"MSFT\"}\u001b[0m  \u001b[32m503.3200\u001b[0m                  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_current_stock…\u001b[0m  \u001b[33m{\"symbol\": \u001b[0m         \u001b[32m180.1900\u001b[0m                  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"GOOGL\"}\u001b[0m                                      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_analyst_recom…\u001b[0m  \u001b[33m{\"symbol\": \"AAPL\"}\u001b[0m  \u001b[32m{\"0\":{\"period\":\"0…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_analyst_recom…\u001b[0m  \u001b[33m{\"symbol\": \"MSFT\"}\u001b[0m  \u001b[32m{\"0\":{\"period\":\"0…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_analyst_recom…\u001b[0m  \u001b[33m{\"symbol\": \u001b[0m         \u001b[32m{\"0\":{\"period\":\"0…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"GOOGL\"}\u001b[0m                                      \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_news\u001b[0m    \u001b[33m{\"symbol\": \"AAPL\",\u001b[0m  \u001b[32m[\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"num_stories\": 5}\u001b[0m   \u001b[32m  {\u001b[0m                       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m    \"id\": \u001b[0m                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m\"68b1079a-3666-36…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_news\u001b[0m    \u001b[33m{\"symbol\": \"MSFT\",\u001b[0m  \u001b[32m[\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"num_stories\": 5}\u001b[0m   \u001b[32m  {\u001b[0m                       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m    \"id\": \u001b[0m                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m\"8221f85a-11f6-35…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m  \u001b[36mget_company_news\u001b[0m    \u001b[33m{\"symbol\": \u001b[0m         \u001b[32m[\u001b[0m                         \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"GOOGL\", \u001b[0m           \u001b[32m  {\u001b[0m                       \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                      \u001b[33m\"num_stories\": 5}\u001b[0m   \u001b[32m    \"id\": \u001b[0m                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                          \u001b[32m\"a3c6b5e3-a60a-32…\u001b[0m        \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭────────────────────── </span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; font-weight: bold\">Upsonic - Call Result</span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\"> ───────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">LLM Model:</span>        openai/gpt-4o                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Result:</span>           <span style=\"color: #008000; text-decoration-color: #008000\"># Comprehensive Market Analysis Report</span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">## Overview</span>                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">This report provides an in-depth </span>               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">analysis of Apple Inc. (AAPL), Microsoft</span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Corporation (MSFT), and Alphabet Inc. </span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">(GOOGL), covering market fundamentals, </span>         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">financial performance, and risk </span>                <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">assessments. Each company operates in </span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">distinct sectors and plays pivotal roles</span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">in the technology industry.</span>                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">---</span>                                             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">## Apple Inc. (AAPL)</span>                            <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">[bold white]...[/bold white]</span>                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Response Format:</span>  &lt;class 'str'&gt;                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Estimated Cost:</span>   ~$0.0639$                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Time Taken:</span>       21.05 seconds                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m─────────────────────\u001b[0m\u001b[37m \u001b[0m\u001b[1;37mUpsonic - Call Result\u001b[0m\u001b[37m \u001b[0m\u001b[37m──────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mLLM Model:\u001b[0m        openai/gpt-4o                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResult:\u001b[0m           \u001b[32m# Comprehensive Market Analysis Report\u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m## Overview\u001b[0m                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mThis report provides an in-depth \u001b[0m               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32manalysis of Apple Inc. (AAPL), Microsoft\u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mCorporation (MSFT), and Alphabet Inc. \u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m(GOOGL), covering market fundamentals, \u001b[0m         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mfinancial performance, and risk \u001b[0m                \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32massessments. Each company operates in \u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mdistinct sectors and plays pivotal roles\u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32min the technology industry.\u001b[0m                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m---\u001b[0m                                             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m## Apple Inc. (AAPL)\u001b[0m                            \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m[bold white]...[/bold white]\u001b[0m                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResponse Format:\u001b[0m  <class 'str'>                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mEstimated Cost:\u001b[0m   ~$0.0639$                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mTime Taken:\u001b[0m       21.05 seconds                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080\">╭──────────────────── </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Upsonic - Price ID Summary</span><span style=\"color: #800080; text-decoration-color: #800080\"> ────────────────────╮</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Price ID:</span>              <span style=\"color: #800080; text-decoration-color: #800080\">8bedfb81-ec7b-4e12-81ce-eead44fddf…</span>        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>                                                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Input Tokens:</span>          <span style=\"color: #800080; text-decoration-color: #800080\">21,282</span>                                     <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Output Tokens:</span>         <span style=\"color: #800080; text-decoration-color: #800080\">1,065</span>                                      <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Total Estimated Cost:</span>  <span style=\"color: #800080; text-decoration-color: #800080\">$0.0639</span>                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[35m╭─\u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m \u001b[0m\u001b[1;35mUpsonic - Price ID Summary\u001b[0m\u001b[35m \u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mPrice ID:\u001b[0m              \u001b[35m8bedfb81-ec7b-4e12-81ce-eead44fddf…\u001b[0m        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m                                                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mInput Tokens:\u001b[0m          \u001b[35m21,282\u001b[0m                                     \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mOutput Tokens:\u001b[0m         \u001b[35m1,065\u001b[0m                                      \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mTotal Estimated Cost:\u001b[0m  \u001b[35m$0.0639\u001b[0m                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "## Stock Analyst Report\n",
      "\n",
      "# Comprehensive Market Analysis Report\n",
      "\n",
      "## Overview\n",
      "\n",
      "This report provides an in-depth analysis of Apple Inc. (AAPL), Microsoft Corporation (MSFT), and Alphabet Inc. (GOOGL), covering market fundamentals, financial performance, and risk assessments. Each company operates in distinct sectors and plays pivotal roles in the technology industry.\n",
      "\n",
      "---\n",
      "\n",
      "## Apple Inc. (AAPL)\n",
      "\n",
      "### Market Research 📊\n",
      "\n",
      "- **Industry & Sector**: Operates in Consumer Electronics within the Technology sector.\n",
      "- **Performance**: Current stock price at $211.16, with a 52-week range of $169.21 - $260.10.\n",
      "- **Market Cap**: Approximately $3.15 trillion.\n",
      "  \n",
      "### Financial Analysis 💹\n",
      "\n",
      "- **Key Ratios**:\n",
      "  - **PE Ratios**: Trailing PE - 32.89, Forward PE - 25.41.\n",
      "  - **Dividend Yield**: 0.51%.\n",
      "  - **Profit Margins**: 24.30%.\n",
      "- **Analyst Sentiments**: Generally positive with a 'Buy' rating.\n",
      "\n",
      "### Risk Assessment 🎯\n",
      "\n",
      "- **Overall Risk**: Low, with an emphasis on governance and shareholder rights.\n",
      "- **Market Risks**: High beta at 1.211 indicating price volatility.\n",
      "- **Company-Specific Challenges**: Concerns around leadership changes and China market dependency.\n",
      "- **Macroeconomic Factors**: Global supply chain issues affecting electronics.\n",
      "\n",
      "---\n",
      "\n",
      "## Microsoft Corporation (MSFT)\n",
      "\n",
      "### Market Research 📊\n",
      "\n",
      "- **Industry & Sector**: Software - Infrastructure under the Technology sector.\n",
      "- **Performance**: Stock trades at $503.32, with a 52-week range of $344.79 - $506.78.\n",
      "- **Market Cap**: Approximately $3.74 trillion.\n",
      "  \n",
      "### Financial Analysis 💹\n",
      "\n",
      "- **Key Ratios**:\n",
      "  - **PE Ratios**: Trailing PE - 38.90, Forward PE - 33.67.\n",
      "  - **Profit Margins**: 35.79%.\n",
      "  - **Dividend Yield**: 0.67%.\n",
      "- **Analyst Recommendations**: Strong 'Buy' with continued confidence in Azure and cloud services growth.\n",
      "\n",
      "### Risk Assessment 🎯\n",
      "\n",
      "- **Overall Risk**: Moderate due to diversification in products and services.\n",
      "- **Market Risks**: Potential regulatory actions impacting its software monopoly.\n",
      "- **Company-Specific Challenges**: Competing with aggressive players in cloud computing and AI.\n",
      "- **Key Catalysts**: Expansion in AI capabilities and cloud services.\n",
      "\n",
      "---\n",
      "\n",
      "## Alphabet Inc. (GOOGL)\n",
      "\n",
      "### Market Research 📊\n",
      "\n",
      "- **Industry & Sector**: Internet Content & Information within the Communication Services sector.\n",
      "- **Performance**: Price at $180.19, with a 52-week range of $140.53 - $207.05.\n",
      "- **Market Cap**: Around $2.19 trillion.\n",
      "  \n",
      "### Financial Analysis 💹\n",
      "\n",
      "- **Key Ratios**:\n",
      "  - **PE Ratios**: PE - 20.11 Forward & Trailing.\n",
      "  - **Profit Margins**: 30.86%.\n",
      "- **Analyst Opinions**: Strong 'Buy', based on advances in digital advertising and cloud services.\n",
      "\n",
      "### Risk Assessment 🎯\n",
      "\n",
      "- **Overall Risk**: High, impacted by governance and compensation risks.\n",
      "- **Company Challenges**: Facing antitrust regulations and data privacy issues.\n",
      "- **Competitive Position**: Leverages strong digital ad market position and investments in AI.\n",
      "- **Macroeconomic Influences**: Fluctuating ad revenues based on economic conditions.\n",
      "\n",
      "---\n",
      "\n",
      "## Conclusion\n",
      "\n",
      "- **Apple** demonstrates robust profit margins but faces potential headwinds in leadership and market pressures in China.\n",
      "- **Microsoft** is well-positioned with continued growth in cloud computing despite regulatory hurdles.\n",
      "- **Alphabet** holds a strong competitive edge in digital advertising, though regulatory risks persist.\n",
      "\n",
      "This analysis underscores the potential growth trajectories and challenges faced by these tech giants, essential for making informed investment decisions.\n"
     ]
    }
   ],
   "source": [
    "from upsonic import Agent, Task\n",
    "from upsonic.tools import YFinanceTools\n",
    "from textwrap import dedent\n",
    "\n",
    "yfinance_tools = YFinanceTools(\n",
    "    company_info=True,\n",
    "    analyst_recommendations=True,\n",
    "    company_news=True,\n",
    "    stock_price=True,\n",
    "    enable_all=True\n",
    ")\n",
    "\n",
    "stock_analyst = Agent(name=\"Stock Analyst\")\n",
    "research_analyst = Agent(name=\"Research Analyst\")\n",
    "investment_lead = Agent(name=\"Investment Lead\")\n",
    "\n",
    "\n",
    "companies = \"AAPL, MSFT, GOOGL\" \n",
    "\n",
    "task1 = Task(\n",
    "    description=dedent(f\"\"\"\\\n",
    "        You are MarketMaster-X, an elite Senior Investment Analyst at Goldman Sachs with expertise in:\n",
    "        - Comprehensive market analysis\n",
    "        - Financial statement evaluation\n",
    "        - Industry trend identification\n",
    "        - News impact assessment\n",
    "        - Risk factor analysis\n",
    "        - Growth potential evaluation\n",
    "\n",
    "        Instructions:\n",
    "        1. Market Research 📊\n",
    "           - Analyze company fundamentals and metrics\n",
    "           - Review recent market performance\n",
    "           - Evaluate competitive positioning\n",
    "           - Assess industry trends and dynamics\n",
    "        2. Financial Analysis 💹\n",
    "           - Examine key financial ratios\n",
    "           - Review analyst recommendations\n",
    "           - Analyze recent news impact\n",
    "           - Identify growth catalysts\n",
    "        3. Risk Assessment 🎯\n",
    "           - Evaluate market risks\n",
    "           - Assess company-specific challenges\n",
    "           - Consider macroeconomic factors\n",
    "           - Identify potential red flags\n",
    "        Note: This analysis is for educational purposes only.\n",
    "\n",
    "        Analyze the following companies and produce a comprehensive market analysis report in markdown format: {companies}\n",
    "    \"\"\"),\n",
    "    tools=yfinance_tools.functions()\n",
    ")\n",
    "report1 = stock_analyst.do(task1)\n",
    "print(\"## Stock Analyst Report\\n\")\n",
    "print(report1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "741a05ff",
   "metadata": {},
   "source": [
    "# Research Analyst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25741c40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭────────────────────── </span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; font-weight: bold\">Upsonic - Call Result</span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\"> ───────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">LLM Model:</span>        openai/gpt-4o                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Result:</span>           <span style=\"color: #008000; text-decoration-color: #008000\"># Investment Analysis and Company </span>              <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Ranking Report</span>                                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">## Overview</span>                                     <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">This report evaluates the investment </span>           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">potential of three leading technology </span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">companies: Apple Inc. (AAPL), Microsoft </span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Corporation (MSFT), and Alphabet Inc. </span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">(GOOGL). These companies have been </span>             <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">assessed on their market fundamentals, </span>         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">financial performance, and risk factors </span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">to provide a comprehensive investment </span>          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">op[bold white]...[/bold white]</span>                  <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Response Format:</span>  &lt;class 'str'&gt;                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Estimated Cost:</span>   ~$0.0118$                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Time Taken:</span>       14.57 seconds                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m─────────────────────\u001b[0m\u001b[37m \u001b[0m\u001b[1;37mUpsonic - Call Result\u001b[0m\u001b[37m \u001b[0m\u001b[37m──────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mLLM Model:\u001b[0m        openai/gpt-4o                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResult:\u001b[0m           \u001b[32m# Investment Analysis and Company \u001b[0m              \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mRanking Report\u001b[0m                                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m## Overview\u001b[0m                                     \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mThis report evaluates the investment \u001b[0m           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mpotential of three leading technology \u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mcompanies: Apple Inc. (AAPL), Microsoft \u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mCorporation (MSFT), and Alphabet Inc. \u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m(GOOGL). These companies have been \u001b[0m             \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32massessed on their market fundamentals, \u001b[0m         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mfinancial performance, and risk factors \u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mto provide a comprehensive investment \u001b[0m          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mop[bold white]...[/bold white]\u001b[0m                  \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResponse Format:\u001b[0m  <class 'str'>                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mEstimated Cost:\u001b[0m   ~$0.0118$                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mTime Taken:\u001b[0m       14.57 seconds                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080\">╭──────────────────── </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Upsonic - Price ID Summary</span><span style=\"color: #800080; text-decoration-color: #800080\"> ────────────────────╮</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Price ID:</span>              <span style=\"color: #800080; text-decoration-color: #800080\">819703c2-c637-4c3e-8611-78698a4486…</span>        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>                                                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Input Tokens:</span>          <span style=\"color: #800080; text-decoration-color: #800080\">1,380</span>                                      <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Output Tokens:</span>         <span style=\"color: #800080; text-decoration-color: #800080\">834</span>                                        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Total Estimated Cost:</span>  <span style=\"color: #800080; text-decoration-color: #800080\">$0.0118</span>                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[35m╭─\u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m \u001b[0m\u001b[1;35mUpsonic - Price ID Summary\u001b[0m\u001b[35m \u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mPrice ID:\u001b[0m              \u001b[35m819703c2-c637-4c3e-8611-78698a4486…\u001b[0m        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m                                                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mInput Tokens:\u001b[0m          \u001b[35m1,380\u001b[0m                                      \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mOutput Tokens:\u001b[0m         \u001b[35m834\u001b[0m                                        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mTotal Estimated Cost:\u001b[0m  \u001b[35m$0.0118\u001b[0m                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "## Research Analyst Report\n",
      "\n",
      "# Investment Analysis and Company Ranking Report\n",
      "\n",
      "## Overview\n",
      "\n",
      "This report evaluates the investment potential of three leading technology companies: Apple Inc. (AAPL), Microsoft Corporation (MSFT), and Alphabet Inc. (GOOGL). These companies have been assessed on their market fundamentals, financial performance, and risk factors to provide a comprehensive investment opportunity evaluation.\n",
      "\n",
      "---\n",
      "\n",
      "## Investment Analysis 🔍\n",
      "\n",
      "### Apple Inc. (AAPL)\n",
      "\n",
      "- **Potential**: Strong due to robust profit margins and a strong brand presence. The company's consumer electronics remain in high demand worldwide.\n",
      "- **Valuation**: Current PE ratios suggest a relatively high valuation but are indicative of market confidence in future earnings.\n",
      "- **Competitive Advantages**: Brand loyalty, ecosystem of products and services, and innovation in technology.\n",
      "- **Market Positioning**: Well-positioned as a leader in consumer electronics but faces challenges due to its dependency on the China market and leadership changes.\n",
      "\n",
      "### Microsoft Corporation (MSFT)\n",
      "\n",
      "- **Potential**: High, driven by its dominant position in cloud services and software infrastructure.\n",
      "- **Valuation**: Higher PE ratios reflect market expectations for strong growth, particularly in Azure and other cloud-based services.\n",
      "- **Competitive Advantages**: Diversified product portfolio, strong enterprise presence, and leading position in AI development.\n",
      "- **Market Positioning**: Well-positioned with a robust business model that leverages growth opportunities in AI and cloud services. \n",
      "\n",
      "### Alphabet Inc. (GOOGL)\n",
      "\n",
      "- **Potential**: Substantial, owing to its expertise in digital advertising and advancements in AI.\n",
      "- **Valuation**: Attractive PE ratios suggest the stock is not overly expensive relative to expected earning prospects.\n",
      "- **Competitive Advantages**: Dominant position in online advertising and strategic investments in AI and cloud infrastructure.\n",
      "- **Market Positioning**: Strong, but faces regulatory scrutiny and economic headwinds impacting ad revenue.\n",
      "\n",
      "---\n",
      "\n",
      "## Risk Evaluation 📈\n",
      "\n",
      "### Apple Inc. (AAPL)\n",
      "\n",
      "- **Risk Factors**: Moderate, with low overall risk but susceptibility to market risks due to high beta.\n",
      "- **Market Conditions**: Challenges from global supply chain disruptions.\n",
      "- **Growth Sustainability**: Potential headwinds from leadership changes and geopolitical tensions with China.\n",
      "- **Management Capability**: Strong, but requires careful succession planning to mitigate leadership transition risks.\n",
      "\n",
      "### Microsoft Corporation (MSFT)\n",
      "\n",
      "- **Risk Factors**: Moderate, facing potential regulatory interventions but offset by strong business diversification.\n",
      "- **Market Conditions**: Strategic focus on emerging sectors like cloud and AI reduces market risks.\n",
      "- **Growth Sustainability**: Robust with continued innovation and product development.\n",
      "- **Management Capability**: Excellent, with a track record of strategic vision and execution.\n",
      "\n",
      "### Alphabet Inc. (GOOGL)\n",
      "\n",
      "- **Risk Factors**: High, primarily due to regulatory challenges on privacy and antitrust.\n",
      "- **Market Conditions**: Economic conditions impact digital ad revenues, but investments in AI provide partial offsets.\n",
      "- **Growth Sustainability**: Relatively strong, driven by its core advertising business and new ventures in cloud and AI.\n",
      "- **Management Capability**: Strong, but must navigate regulatory landscape carefully.\n",
      "\n",
      "---\n",
      "\n",
      "## Company Ranking 🏆\n",
      "\n",
      "1. **Microsoft Corporation (MSFT)**\n",
      "   - **Rationale**: Despite a higher valuation, Microsoft's diversification across cloud services and AI, combined with solid profit margins and a strategic growth plan, make it the top investment choice. The company shows low-risk high-reward potential into the foreseeable future.\n",
      "\n",
      "2. **Alphabet Inc. (GOOGL)**\n",
      "   - **Rationale**: Attractive valuation with a leading position in digital advertising and strong growth prospects in AI make Alphabet a compelling investment. However, higher risk due to regulatory pressure requires consideration of risk-adjusted returns.\n",
      "\n",
      "3. **Apple Inc. (AAPL)**\n",
      "   - **Rationale**: Though Apple has significant competitive advantages like brand loyalty and innovation, potential market vulnerabilities—such as dependency on China—diminish its investment attractiveness relative to the other two firms.\n",
      "\n",
      "These rankings consider both investment potential and risk-adjusted returns, providing a detailed foundation for strategic recommendations in the technology sector.\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "task2 = Task(\n",
    "    description=dedent(f\"\"\"\\\n",
    "        You are ValuePro-X, an elite Senior Research Analyst at Goldman Sachs specializing in:\n",
    "        - Investment opportunity evaluation\n",
    "        - Comparative analysis\n",
    "        - Risk-reward assessment\n",
    "        - Growth potential ranking\n",
    "        - Strategic recommendations\n",
    "\n",
    "        Instructions:\n",
    "        1. Investment Analysis 🔍\n",
    "           - Evaluate each company's potential\n",
    "           - Compare relative valuations\n",
    "           - Assess competitive advantages\n",
    "           - Consider market positioning\n",
    "        2. Risk Evaluation 📈\n",
    "           - Analyze risk factors\n",
    "           - Consider market conditions\n",
    "           - Evaluate growth sustainability\n",
    "           - Assess management capability\n",
    "        3. Company Ranking 🏆\n",
    "           - Rank based on investment potential\n",
    "           - Provide detailed rationale\n",
    "           - Consider risk-adjusted returns\n",
    "           - Explain competitive advantages\n",
    "\n",
    "        Based on the following market analysis, rank the companies by investment potential and provide a detailed investment analysis and ranking report in markdown format:\n",
    "\n",
    "        {report1}\n",
    "    \"\"\"),\n",
    "    tools=[]\n",
    ")\n",
    "report2 = research_analyst.do(task2)\n",
    "print(\"\\n## Research Analyst Report\\n\")\n",
    "print(report2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fc986be",
   "metadata": {},
   "source": [
    "# Investment Lead"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca2cbd56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╭────────────────────── </span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; font-weight: bold\">Upsonic - Call Result</span><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\"> ───────────────────────╮</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">LLM Model:</span>        openai/gpt-4o                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Result:</span>           <span style=\"color: #008000; text-decoration-color: #008000\"># Investment Portfolio Strategy and </span>            <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Recommendation Report</span>                           <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">## Portfolio Strategy 💼</span>                        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">### Allocation Strategy</span>                         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">Based on the given company ranking and </span>         <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">analysis, the portfolio allocation will </span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">be distributed as follows:</span>                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">1. **Microsoft Corporation (MSFT): 40%**</span>        <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">2. **Alphabet Inc. (GOOGL): 35%**</span>               <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">3. **Apple Inc. (AAPL): 25%**</span>                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">### Risk-Reward Optimization</span>                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">- **Diversification*[bold </span>                      <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                    <span style=\"color: #008000; text-decoration-color: #008000\">white]...[/bold white]</span>                          <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>                                                                    <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Response Format:</span>  &lt;class 'str'&gt;                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Estimated Cost:</span>   ~$0.0114$                                       <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>  <span style=\"font-weight: bold\">Time Taken:</span>       19.96 seconds                                   <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">│</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[37m╭─\u001b[0m\u001b[37m─────────────────────\u001b[0m\u001b[37m \u001b[0m\u001b[1;37mUpsonic - Call Result\u001b[0m\u001b[37m \u001b[0m\u001b[37m──────────────────────\u001b[0m\u001b[37m─╮\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mLLM Model:\u001b[0m        openai/gpt-4o                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResult:\u001b[0m           \u001b[32m# Investment Portfolio Strategy and \u001b[0m            \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mRecommendation Report\u001b[0m                           \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m## Portfolio Strategy 💼\u001b[0m                        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m### Allocation Strategy\u001b[0m                         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mBased on the given company ranking and \u001b[0m         \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32manalysis, the portfolio allocation will \u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mbe distributed as follows:\u001b[0m                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m1. **Microsoft Corporation (MSFT): 40%**\u001b[0m        \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m2. **Alphabet Inc. (GOOGL): 35%**\u001b[0m               \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m3. **Apple Inc. (AAPL): 25%**\u001b[0m                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m### Risk-Reward Optimization\u001b[0m                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32m- **Diversification*[bold \u001b[0m                      \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                    \u001b[32mwhite]...[/bold white]\u001b[0m                          \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m                                                                    \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mResponse Format:\u001b[0m  <class 'str'>                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mEstimated Cost:\u001b[0m   ~$0.0114$                                       \u001b[37m│\u001b[0m\n",
       "\u001b[37m│\u001b[0m  \u001b[1mTime Taken:\u001b[0m       19.96 seconds                                   \u001b[37m│\u001b[0m\n",
       "\u001b[37m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080\">╭──────────────────── </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Upsonic - Price ID Summary</span><span style=\"color: #800080; text-decoration-color: #800080\"> ────────────────────╮</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Price ID:</span>              <span style=\"color: #800080; text-decoration-color: #800080\">3b405188-4084-47a3-8819-45cd04fef8…</span>        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>                                                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Input Tokens:</span>          <span style=\"color: #800080; text-decoration-color: #800080\">1,480</span>                                      <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Output Tokens:</span>         <span style=\"color: #800080; text-decoration-color: #800080\">772</span>                                        <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">│</span>  <span style=\"font-weight: bold\">Total Estimated Cost:</span>  <span style=\"color: #800080; text-decoration-color: #800080\">$0.0114</span>                                    <span style=\"color: #800080; text-decoration-color: #800080\">│</span>\n",
       "<span style=\"color: #800080; text-decoration-color: #800080\">╰────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[35m╭─\u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m \u001b[0m\u001b[1;35mUpsonic - Price ID Summary\u001b[0m\u001b[35m \u001b[0m\u001b[35m───────────────────\u001b[0m\u001b[35m─╮\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mPrice ID:\u001b[0m              \u001b[35m3b405188-4084-47a3-8819-45cd04fef8…\u001b[0m        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m                                                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mInput Tokens:\u001b[0m          \u001b[35m1,480\u001b[0m                                      \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mOutput Tokens:\u001b[0m         \u001b[35m772\u001b[0m                                        \u001b[35m│\u001b[0m\n",
       "\u001b[35m│\u001b[0m  \u001b[1mTotal Estimated Cost:\u001b[0m  \u001b[35m$0.0114\u001b[0m                                    \u001b[35m│\u001b[0m\n",
       "\u001b[35m╰────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "## Investment Lead Report\n",
      "\n",
      "# Investment Portfolio Strategy and Recommendation Report\n",
      "\n",
      "## Portfolio Strategy 💼\n",
      "\n",
      "### Allocation Strategy\n",
      "Based on the given company ranking and analysis, the portfolio allocation will be distributed as follows:\n",
      "\n",
      "1. **Microsoft Corporation (MSFT): 40%**\n",
      "2. **Alphabet Inc. (GOOGL): 35%**\n",
      "3. **Apple Inc. (AAPL): 25%**\n",
      "\n",
      "### Risk-Reward Optimization\n",
      "- **Diversification**: This allocation balances exposure across three leading tech companies, optimizing for both growth potential and risk management.\n",
      "- **Risk Management**: MSFT is given the highest allocation due to its lower risk and strong growth prospects in emerging sectors like cloud and AI. Despite GOOGL's regulatory risks, its valuation attractiveness and growth in AI justify a substantial allocation.\n",
      "- **Timeframe**: The strategy is based on a medium to long-term growth perspective, leveraging technological advancements and market leadership positions.\n",
      "\n",
      "## Investment Rationale 📝\n",
      "\n",
      "### Overview\n",
      "\n",
      "- **Microsoft Corporation (MSFT)**: With Microsoft's strategic focus on AI and cloud services, bolstered by a diversified product base, the company presents a robust risk-reward profile. Its strategic management and enterprise presence ensure a sustainable growth trajectory.\n",
      "  \n",
      "- **Alphabet Inc. (GOOGL)**: Despite the regulatory pressures, Alphabet's valuation is attractive, and its leadership in digital advertising and AI initiatives provide a strong growth catalyst. The focus on cloud infrastructure investments will also drive long-term value.\n",
      "\n",
      "- **Apple Inc. (AAPL)**: While Apple enjoys significant competitive advantages like brand loyalty, its over-reliance on the China market and high beta risk could pose potential vulnerabilities. Nevertheless, its continued innovation secures a place in the portfolio.\n",
      "\n",
      "### Potential Concerns\n",
      "- **MSFT**: Regulatory interventions could impact business operations, but strong diversification mitigates major risks.\n",
      "- **GOOGL**: Regulatory headwinds might affect short-term performance, yet long-term AI investments are likely to provide growth offsets.\n",
      "- **AAPL**: Global supply chain disruptions and leadership changes may impact performance, necessitating vigilant risk management.\n",
      "\n",
      "### Growth Catalysts\n",
      "- **MSFT**: Expansion in cloud services and AI offers significant growth potential.\n",
      "- **GOOGL**: AI strategic ventures and cloud growth initiatives.\n",
      "- **AAPL**: New product lines and enhanced consumer electronics ecosystem.\n",
      "\n",
      "## Recommendation Delivery 📊\n",
      "\n",
      "### Summary Allocations\n",
      "- **Microsoft Corporation (MSFT): 40%** - Investment focus on leveraging growth in cloud services and AI technologies.\n",
      "- **Alphabet Inc. (GOOGL): 35%** - Capitalize on undervaluation and strategic movements in AI and cloud services.\n",
      "- **Apple Inc. (AAPL): 25%** - Maintain exposure for consumer electronics innovation and brand resilience.\n",
      "\n",
      "### Investment Thesis\n",
      "This portfolio is designed to withstand foreseeable regulatory and market risks by diversifying across three high-potential, leading tech firms. The strategic emphasis is on maximizing long-term growth opportunities, particularly in AI and cloud services.\n",
      "\n",
      "### Actionable Insights\n",
      "- **Regular Monitoring**: Closely observe regulatory developments affecting GOOGL and adjust allocations as necessary.\n",
      "- **Market Adaptation**: Keep abreast of supply chain challenges impacting AAPL and re-balance if risks intensify.\n",
      "- **Strategic Reassessment**: Reevaluate the portfolio allocation periodically to optimize for emerging opportunities and risk shifts.\n",
      "\n",
      "### Risk Considerations\n",
      "- **Technology Sector Volatility**: While high-growth, tech stocks are susceptible to volatility—consider hedging positions if market risks heighten.\n",
      "- **Global Economic Conditions**: Monitor global economic indicators that may impact market demand or supply chain continuity.\n",
      "\n",
      "This investment strategy delivers a balanced portfolio with a focus on sustainable long-term growth by capitalizing on each company's strengths while mindfully addressing their respective risks.\n"
     ]
    }
   ],
   "source": [
    "task3 = Task(\n",
    "    description=dedent(f\"\"\"\\\n",
    "        You are PortfolioSage-X, a distinguished Senior Investment Lead at Goldman Sachs expert in:\n",
    "        - Portfolio strategy development\n",
    "        - Asset allocation optimization\n",
    "        - Risk management\n",
    "        - Investment rationale articulation\n",
    "        - Client recommendation delivery\n",
    "\n",
    "        Instructions:\n",
    "        1. Portfolio Strategy 💼\n",
    "           - Develop allocation strategy\n",
    "           - Optimize risk-reward balance\n",
    "           - Consider diversification\n",
    "           - Set investment timeframes\n",
    "        2. Investment Rationale 📝\n",
    "           - Explain allocation decisions\n",
    "           - Support with analysis\n",
    "           - Address potential concerns\n",
    "           - Highlight growth catalysts\n",
    "        3. Recommendation Delivery 📊\n",
    "           - Present clear allocations\n",
    "           - Explain investment thesis\n",
    "           - Provide actionable insights\n",
    "           - Include risk considerations\n",
    "\n",
    "        Based on the following investment analysis and ranking, develop a portfolio allocation strategy and provide a final investment report in markdown format:\n",
    "\n",
    "        {report2}\n",
    "    \"\"\"),\n",
    "    tools=[]\n",
    ")\n",
    "final_report = investment_lead.do(task3)\n",
    "print(\"\\n## Investment Lead Report\\n\")\n",
    "print(final_report)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ab974f06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "All reports have been saved to investment_full_report.md\n"
     ]
    }
   ],
   "source": [
    "# Combine all reports into one markdown string\n",
    "all_reports_md = (\n",
    "    \"# Stock Analyst Report\\n\\n\"\n",
    "    f\"{report1}\\n\\n\"\n",
    "    \"# Research Analyst Report\\n\\n\"\n",
    "    f\"{report2}\\n\\n\"\n",
    "    \"# Investment Lead Report\\n\\n\"\n",
    "    f\"{final_report}\\n\"\n",
    ")\n",
    "\n",
    "# Write to a markdown file\n",
    "with open(\"investment_full_report.md\", \"w\") as f:\n",
    "    f.write(all_reports_md)\n",
    "\n",
    "print(\"All reports have been saved to investment_full_report.md\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "880bd522",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "upsonic",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
